/*
 * @Author: zxh
 * @Date: 2024-07-26 16:09:57
 * @LastEditors: zxh
 * @LastEditTime: 2024-07-26 16:23:48
 * @Description: 请填写简介
 */

import { install } from 'element-plus'
import { useIntersectionObserver } from '@vueuse/core'

//定义懒加载插件
export const lazyPlugin = {
  install(app: any) {
    // 懒加载指令逻辑
    app.directive('img-lazy', {
      mounted(el: any, binding: any) {
        const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => {
          if (isIntersecting) {
            // 进入视口区域
            el.src = binding.value
            stop()
          }
        })
      }
    })
  }
}
